define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {



    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sms_send/index',
                    add_url: 'sms_send/add',
                    // edit_url: 'sms_send/edit',
                    // del_url: 'sms_send/del',
                    multi_url: 'sms_send/multi',
                    table: 'sms_send',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field : 'content', title: '内容',cellStyle: function () {return {css: {"max-width": "200px","overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}}, operate: 'LIKE', align: 'left',formatter:Controller.api.formatter.content },
                        /*{field: 'id', title: __('Id')},*/
                        {field: 'mobile', title: __('Sms_send_mobile'),operate:'LIKE'},
                        {field: 'content', title: __('Sms_send_content'),width:400,formatter: function(value){return value.toString().substr(0, 100)},operate:false},
                        {field: 'goods_id', title: __('Sms_send_goods_id'),operate:false},
                        {field: 'goods_name', title: __('Sms_send_goods_name'),operate:'LIKE'},
                       // {field: 'status', title: __('Status')},
                        // {field: 'status', title: __('Status'),searchList:{"0":__('normal'),"1":__('handed'),"2":__('past'),"3":__('delete')},formatter: Table.api.formatter.normal},
                      /*  {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},*/
                        {field: 'createtime', title: __('Add_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate:false},
                        /*{field: 'del_time', title: __('Del_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            table.off('dbl-click-row.bs.table');
        },
        add: function () {
            $("#c-coupon_code").data("params", function (obj) {
                return {custom: {brand_id: $("#c-brand_id").val()}};
            });
            $(document).on("change", "#c-goods_id", function(){
            	var id = $(this).val();
			    $.post({
                    url: 'sms_send/getName',
                    dataType: 'json',
                    data: {id: id},
                    cache: false,
                    success: function (ret) {
                    	$('.goods_name').val(ret);
                    	var content = '中国电信提醒您，前往微信点击链接领取翼生活代金券，全省链接：https://ty.jfxxl.net/?authorization=1    '+ret+'链接：https://ty.jfxxl.net/#/home/details?id='+id+'&authorization=1，详情请拨打翼生活客服电话4001088679咨询，感谢您的支持，祝您生活愉快！回T退订'
                    	$('#c-content').val(content);
                        // console.log(ret);
                    }, error: function () {
                        Toastr.error(__('Network error'));
                    }
                });
			    // console.log($(this).val());
			    // $('#c-goods_id_text').val();
			});
            $(".selectpicker").change(function(){
            	var type = $(this).val();
            	var content;
            	if(type == 1){
            		//给所选短信赋值  1 代表无权益
            		//把权益选择隐藏
            		$('.goods').hide();
            		content = "中国电信提醒您，前往微信点击链接领取翼生活代金券，全省链接：https://ty.jfxxl.net/?authorization=1，详情请拨打翼生活客服电话4001088679咨询，感谢您的支持，祝您生活愉快！回T退订";
            		
            	}else{
            		content = "中国电信提醒您，前往微信点击链接领取翼生活代金券，全省链接：https://ty.jfxxl.net/?authorization=1     {参数1}链接：https://ty.jfxxl.net/#/home/details?id={参数2}&authorization=1，详情请拨打翼生活客服电话4001088679咨询，感谢您的支持，祝您生活愉快！回T退订";
            		$('.goods').show();
            		$('.goods').attr('data-rule','required');
            	}
            	$('#c-content').val(content);
			  	
			});
            Controller.api.bindevent();
        },
        // edit: function () {
        //     Controller.api.bindevent();
        // },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});